package com.zahb.qadx.ui.adapter;

import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.entity.node.BaseNode;
import com.chad.library.adapter.base.provider.BaseNodeProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.zahb.qadx.R;
import com.zahb.qadx.model.CurriculumChapter;

import org.jetbrains.annotations.NotNull;

/**
 * Created by Zdw on 2020/10/21 16:29
 * 课程目录树首级
 */
public class ChapterProviderStart extends BaseNodeProvider {

    @Override
    public int getItemViewType() {
        return 0;
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_list_chapter_start;
    }

    @Override
    public void convert(@NotNull BaseViewHolder baseViewHolder, BaseNode baseNode) {
        if (baseNode instanceof CurriculumChapter) {
            CurriculumChapter chapter = (CurriculumChapter) baseNode;
            baseViewHolder.setText(R.id.tv_title, chapter.getName());
            ImageView ivArray = baseViewHolder.getView(R.id.iv_array);
            if (chapter.isExpanded()) {
                ivArray.setRotation(180f);
            } else {
                ivArray.setRotation(0f);
            }
        }
    }

    @Override
    public void onClick(@NotNull BaseViewHolder helper, @NotNull View view, BaseNode data, int position) {
        if (getAdapter() != null)
            getAdapter().expandOrCollapse(position, true);
    }
}
